package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.WeatherDao;
import ysq.xyg.model.Weather;
import ysq.xyg.service.WeatherService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-04-19 14:11
 **/
@Service("weatherService")
public class WeatherServiceImpl extends BaseServiceImpl<Weather> implements WeatherService {
    @Resource
    private WeatherDao weatherDao;
    @Autowired
    public void setWeatherDao(WeatherDao weatherDao) {
        this.baseDao = weatherDao;
    }

    //分页查询
    public PageInfo<Weather> pageInfo(Weather weather, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        //通用Example查询
        Example example = new Example(Weather.class);
        Example.Criteria criteria = example.createCriteria();
        if(weather!=null){
            if(StringUtil.isNotEmpty(weather.getDeviceId())){
                criteria.andEqualTo("deviceId",weather.getDeviceId());
            }

        }
        List<Weather> list=weatherDao.selectByExample(example);
        return new PageInfo<Weather>(list);
    }


    public List<Weather> list(Weather weather) {
        //通用Example查询
        Example example = new Example(Weather.class);
        Example.Criteria criteria = example.createCriteria();
        if(weather!=null){
            if(StringUtil.isNotEmpty(weather.getDeviceId())){
                criteria.andEqualTo("deviceId",weather.getDeviceId());
            }
        }
        List<Weather> list=weatherDao.selectByExample(example);
        return list;
    }

}
